# Load affordable housing units data for Charlottesville, VA
housing.units <- read.csv("charlottesville_affordable_housing.csv")

# Load US Census tract data for VA
tract <- readOGR("./cb_2017_51_tract_500k/cb_2017_51_tract_500k.shp", layer = "cb_2017_51_tract_500k", GDAL1_integer64_policy = TRUE)
## OGR data source with driver: ESRI Shapefile 
## Source: "/Users/geoffwork/Documents/GitHub/HW3-Gillikin/cb_2017_51_tract_500k/cb_2017_51_tract_500k.shp", layer: "cb_2017_51_tract_500k"
## with 1900 features
## It has 9 fields
## Integer64 fields read as doubles:  ALAND AWATER
# Load selected Places Path data for Charlottesville
path.interests <- read.csv("places.of.interest.path.csv")
## Warning in read.table(file = file, header = header, sep = sep,
## quote = quote, : incomplete final line found by readTableHeader on
## 'places.of.interest.path.csv'
# Custom color palatte
palet <- colorFactor(c("#4575b4", "#d73027"), c("multiple", "single"))
leaflet() %>%
  # Set custom view
  setView(-78.4800, 38.03, 13) %>%
  # Base Groups ---
  addTiles(group = "OSM (default)") %>%
  addProviderTiles("OpenStreetMap.HOT", group = "HOT") %>%
  addProviderTiles("OpenTopoMap", group = "TopoMap") %>%
  # Overlay Groups ---
  # Add clusters of markers for affordable housing units
  # You renamed your palet function at some point
  addCircleMarkers(data = housing.units, lng = ~long, lat = ~lat, radius = 2, color = ~palet(type), clusterOptions = markerClusterOptions(), group = "Affordable housing units") %>%
  # Add legend for circle markers
  addLegend(position = "topright" , pal = palet, values = housing.units$type, title = "Affordable housing units by type") %>%
  # Add path connecting selected points of interest
  addPolylines(data = path.interests, lng = ~long, lat = ~lat, color = "blue", group = "Path of places of interest") %>%
  # Add census tracts
  addPolygons(data = tract, fill = F, weight = 3, color = "#444444", group = "Census tracts") %>%
  # Layers control ---
  addLayersControl(
    baseGroups = c("OSM (default)", "HOT", "TopoMap"),
    overlayGroups = c("Affordable housing units", "Census tracts", "Path of places of interest"),
    options = layersControlOptions(collapsed = FALSE))